<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateUserVisitTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_visit', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->comment('用户ID');
            $table->integer('visited_user_id')->comment('被访问的用户ID');
            $table->timestamps();
            $table->tinyInteger('flag')->default(1)->comment('状态：0-无效，1-有效');
            $table->index('user_id', 'user_id');
            $table->index('visited_user_id', 'visited_user_id');
            $table->index(['user_id', 'visited_user_id'], 'visit_user');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('user_visit');
    }
}
